local meta = FindMetaTable( "Player" )

function meta:HasRequired(Mixture)
	if #self.Inventory == 0 then return false end
	local Unstacked = {}
	local Matches = 0
	for k,v in pairs(self.Inventory) do
		if v.Stackable && v.Stack > 1 then
			for i=1,v.Stack do table.insert(Unstacked,v.Class) end
		else
			table.insert(Unstacked,v.Class)
		end
	end
	for k,v in pairs(Unstacked) do	
		if table.HasValue(Mixture,v) then
			print("Match Found",Matches)
			Matches = Matches + 1
			print("Match Added",Matches)
		end
	end
	if Matches >= #Mixture then
		print("true",Matches)
		PrintTable(Unstacked)
		return true
	else
		print("false",Matches)
		PrintTable(Unstacked)
		return false
	end
end

function meta:Craft(Mixture)
	for k,v in pairs(Basewars.Mixtures) do
		if v.Class == Mixture then
			PrintTable(v.Requirement)
			print("Check Start")
			if self:HasRequired(v.Requirement) then
				print("Passed")
				for Key,Item in pairs(v.Requirement) do
					print("Removing Item:",Item)
					self:RemoveItem(Item)
				end
					print("Adding Item:",v:Output(self))
					self:AddItem(v:Output(self))
					
				break
			else
				print("Failed")
				break
			end
		end
	end
end

function FindMixture(Mixture)
	for k,v in pairs(Basewars.Mixtures) do
		if v.Class == Mixture then
			return Mixture
		else
			return false
		end	
	end	
end

concommand.Add("CraftItem",function(ply,cmd,arg)
ply:Craft(tostring(arg[1]))
end)

function GM:ShowSpare1(ply)
umsg.Start("ShowCraft",ply)
umsg.End()
end

